<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    // 递归：函数自己调用自己
    // 特点：类似于循环  必须有结束语句
    function getNum(n) {
        if(n==1){
            return 1
        }else {
            return n+getNum(n-1)
        }
    }
    console.log(getNum(20));
</script>
<script>
     // 递归深拷贝
     var obj = {
        name: "zs",
        age: 18,
        object: {
            age: 20,
            aa: {
                age: 10
            }
        },
        arr: [1, 2, 3]

    }
    var newObj = {}
    function recursion(obj, newObj) {
        for (key in obj) {
            if (obj[key].constructor == Object) {
                newObj[key] = {}
                recursion(obj[key], newObj[key])
            } else if (obj[key].constructor == Array) {
                newObj[key] = []
                recursion(obj[key], newObj[key])
            } else {
                newObj[key] = obj[key]
            }
        }
    }
    recursion(obj, newObj)
    newObj.object.aa.age = 40
    console.log(obj);
    console.log(newObj);

    var arr = [1]
    console.log(arr instanceof Object);
</script>
</html>